
/*
 * -- SuperLU MT routine (version 2.0) --
 * Lawrence Berkeley National Lab, Univ. of California Berkeley,
 * and Xerox Palo Alto Research Center.
 * September 10, 2007
 *
 * Sparse matrix types and function prototypes.
 *
 */

#ifndef __SUPERLU_zSP_DEFS /* allow multiple inclusions */
#define __SUPERLU_zSP_DEFS

/*
 * File name:           pzsp_defs.h
 * Purpose:             Sparse matrix types and function prototypes
 * History:
 */

#include "hnum_slucmn.h"

#include "hnum_slu_dcomplex.h"

namespace harlinn
{
    namespace numerics
    {
        namespace SuperLU
        {
            namespace DoubleComplex
            {

                typedef GlobalLU_T<doublecomplex> GlobalLU_t;
                typedef pxgstrf_shared_T<GlobalLU_t> pxgstrf_shared_t;
                typedef pxgstrf_threadarg_T<pxgstrf_shared_t> pzgstrf_threadarg_t;

                /* *********************
                   Function prototypes
                   *********************/

                /* ----------------
                   Driver routines 
                   ---------------*/
                void
                pzgssv(int, SuperMatrix *, int *, int *, SuperMatrix *, SuperMatrix *, 
                       SuperMatrix *, int *);
                void
                pzgssvx(int, superlumt_options_t *, SuperMatrix *, int *, int *,  
	                equed_t *, double *, double *, SuperMatrix *, SuperMatrix *,
	                SuperMatrix *, SuperMatrix *, 
	                double *, double *, double *, double *, superlu_memusage_t *, 
	                int *);

                /* ---------------
                   Driver related 
                   ---------------*/
                void zgsequ (SuperMatrix *, double *, double *, double *,
                                    double *, double *, int *);
                void zlaqgs (SuperMatrix *, double *, double *, double, 
		                    double, double, equed_t *);
                void zgscon (char *, SuperMatrix *, SuperMatrix *,
		                    double, double *, int *);
                double zPivotGrowth(int, SuperMatrix *, int *,
			                   SuperMatrix *, SuperMatrix *);
                void zgsrfs (trans_t, SuperMatrix *, SuperMatrix *, SuperMatrix *,
		                    int *, int *, equed_t, double *, double *, SuperMatrix *,
		                    SuperMatrix *, double *, double *, Gstat_t *, int *);
                int  sp_ztrsv (char *, char *, char *, SuperMatrix *, SuperMatrix *,
		                      doublecomplex *, int *);
                int  sp_zgemv (char *, doublecomplex, SuperMatrix *, doublecomplex *,
		                      int, doublecomplex, doublecomplex *, int);
                int  sp_zgemm (char *, int, int, int, doublecomplex, SuperMatrix *, 
		                      doublecomplex *, int, doublecomplex, doublecomplex *, int);

                /* ----------------------
                   Factorization related
                   ----------------------*/
                

                void
                zCreate_CompCol_Matrix(SuperMatrix *, int, int, int, doublecomplex *,
		                      int *, int *, Stype_t, Dtype_t, Mtype_t);
                void
                zCreate_CompCol_Permuted(SuperMatrix *, int, int, int, doublecomplex *, int *,
			                 int *, int *, Stype_t, Dtype_t, Mtype_t);
                void
                zCopy_CompCol_Matrix(SuperMatrix *, SuperMatrix *);
                void
                zCreate_Dense_Matrix(SuperMatrix *, int, int, doublecomplex *, int,
		                     Stype_t, Dtype_t, Mtype_t);
                void
                zCreate_SuperNode_Matrix(SuperMatrix *, int, int, int, doublecomplex *, int *, int *,
			                int *, int *, int *, Stype_t, Dtype_t, Mtype_t);
                void
                zCreate_SuperNode_Permuted(SuperMatrix *, int, int, int, doublecomplex *, 
			                   int *, int *, int *, int *, int *, int *, 
			                   int *, int *, Stype_t, Dtype_t, Mtype_t);
                void
                zCopy_Dense_Matrix(int, int, doublecomplex *, int, doublecomplex *, int);


                void zallocateA (int, int, doublecomplex **, int **, int **);
                void get_perm_c(int, SuperMatrix *, int *);
                void zsp_colorder (SuperMatrix *, int *, superlumt_options_t *,
			                 SuperMatrix *);
                int  zPresetMap (const int, SuperMatrix *, pxgstrf_relax_t *, 
		                       superlumt_options_t *, GlobalLU_t *);
                int  DynamicSetMap(const int, const int, const int, pxgstrf_shared_t*);
                void pzgstrf (superlumt_options_t *, SuperMatrix *, int *, 
		                     SuperMatrix *, SuperMatrix *, Gstat_t *, int *);
                void pzgstrf_init (int, fact_t, trans_t, yes_no_t, int, int, double, yes_no_t, double,
			                  int *, int *, void *, int, SuperMatrix *,
			                  SuperMatrix *, superlumt_options_t *, Gstat_t *);
                pzgstrf_threadarg_t*
                pzgstrf_thread_init (SuperMatrix *, SuperMatrix *, SuperMatrix *,
		                     superlumt_options_t*, pxgstrf_shared_t*, Gstat_t*, int*);
                void
                pzgstrf_thread_finalize (pzgstrf_threadarg_t *, pxgstrf_shared_t *,
			                 SuperMatrix *, int *, SuperMatrix *, SuperMatrix *);
                void pzgstrf_finalize(superlumt_options_t *, SuperMatrix *);
                int
                pzgstrf_factor_snode (const int, const int, SuperMatrix *, const double,
		                      yes_no_t *, int *, int *, int*, int*, int*, int*,
		                      doublecomplex *, doublecomplex *, pxgstrf_shared_t *, int *);
                void pzgstrf_mark_busy_descends (int, int, int *, pxgstrf_shared_t *, int *, int *);
                int  pzgstrf_snode_dfs (const int, const int, const int, const int *,
			                       const int *, const int *, int*, int *, int *,
			                       pxgstrf_shared_t *);
                int  pzgstrf_snode_bmod (const int, const int, const int, const int,
				                doublecomplex *, doublecomplex *, GlobalLU_t*, Gstat_t*);
                void pzgstrf_panel_dfs (const int, const int, const int, const int,
			                       SuperMatrix *, int*, int*, int*, int*, int*, 
			                       int*, int*, int*, int*, int*, int*, int*, int*,
			                       doublecomplex*, GlobalLU_t *);
                void pzgstrf_panel_bmod (const int, const int, const int, const int,
				                const int, int*, int*, int*, int*, int*, int*,
				                int*, int*, doublecomplex*, doublecomplex*, 
				                pxgstrf_shared_t *);
                void pzgstrf_bmod1D (const int, const int, const int, const int, 
			                    const int, const int, const int, int, int,
			                    int *, int *, int *, int *, doublecomplex *, doublecomplex *, 
			                    GlobalLU_t *, Gstat_t *);
                void pzgstrf_bmod2D (const int, const int, const int, const int,
			                    const int, const int, const int, int, int,
			                    int *, int *, int *, int *, doublecomplex *, doublecomplex *,
			                    GlobalLU_t *, Gstat_t *);
#ifndef _MSC_VER
                void pzgstrf_bmod1D_mv2 (const int, const int, const int, const int, 
				                const int, const int, const int, int, int,
				                int *, int *, int *, int *, doublecomplex *, 
				                doublecomplex *, GlobalLU_t *, Gstat_t *);
                void pzgstrf_bmod2D_mv2 (const int, const int, const int, const int,
				                const int, const int, const int, int, int,
				                int *, int *, int *, int *, doublecomplex *, doublecomplex *,
				                GlobalLU_t *, Gstat_t *);
#endif
                int  pzgstrf_column_dfs(const int, const int, const int, const int,
			                       int*, int*, int*, int, int*, int*, int*, int*,
			                       int *, int *, int *, int *, pxgstrf_shared_t *);
                int  pzgstrf_column_bmod(const int, const int, const int, const int, 
				                int*, int*, doublecomplex*, doublecomplex*,
				                pxgstrf_shared_t *, Gstat_t *);
                int  pzgstrf_pivotL (const int, const int, const double, yes_no_t*,
			                    int*, int*, int*, int*, GlobalLU_t*, Gstat_t*);
                int  pzgstrf_copy_to_ucol (const int, const int, const int, const int *,
				                  const int *, const int *, doublecomplex*,
				                  pxgstrf_shared_t*);
                void pzgstrf_pruneL (const int, const int *, const int, const int,
			                    const int *, const int *, int*, int *,
			                    GlobalLU_t *);
                void compressSUP (const int, GlobalLU_t *);
                
                void zreadmt (int *, int *, int *, doublecomplex **, int **, int **);
                void zreadhb (int *, int *, int *, doublecomplex **, int **, int **);
                void zGenXtrue (int, int, doublecomplex *, int);
                void zFillRHS (trans_t, int, doublecomplex *, int, 
		                      SuperMatrix *, SuperMatrix *);
                void zgstrs (trans_t, SuperMatrix *, SuperMatrix*, 
		                    int*, int*, SuperMatrix*, Gstat_t *, int *);


                /* ---------------
                   Memory related 
                   ---------------*/
                float pzgstrf_MemInit (int, int, superlumt_options_t *,
			                SuperMatrix *, SuperMatrix *, GlobalLU_t *);
                float pzgstrf_memory_use(const int, const int, const int);
                int  pzgstrf_WorkInit (int, int, int **, doublecomplex **);
                void pzgstrf_SetRWork (int, int, doublecomplex *, doublecomplex **, doublecomplex **);
                void pzgstrf_WorkFree (int *, doublecomplex *, GlobalLU_t *);
                int  pzgstrf_MemXpand (int, int, MemType, int *, GlobalLU_t *);

                doublecomplex *doublecomplexMalloc(int);
                doublecomplex *doublecomplexCalloc(int);
                int  memory_usage ();
                int  superlu_zQuerySpace (int, SuperMatrix *, SuperMatrix *, int, 
				                 superlu_memusage_t *);
                int  Glu_alloc (const int, const int, const int, const MemType,
		                       int *, pxgstrf_shared_t *);

                /* -------------------
                   Auxiliary routines
                   -------------------*/
                void    zfill(doublecomplex *, int, doublecomplex);
                void    zinf_norm_error(int, SuperMatrix *, doublecomplex *);
                void    snode_profile(int, int *);
                void    super_stats(int, int *, int *);
                void    panel_stats(int, int, int *, Gstat_t *);
                void    PrintSumm(char *, int, int, int);
                void    zPrintPerf(SuperMatrix *, SuperMatrix *, superlu_memusage_t *,
			                 double, double, double *, double *, char *,
			                 Gstat_t *);
                void    zCompRow_to_CompCol(int m, int n, int nnz, 
                                           doublecomplex *a, int *colind, int *rowptr,
                                           doublecomplex **at, int **rowind, int **colptr);


                /* -----------------------
                   Routines for debugging
                   -----------------------*/
                void    print_lu_col(int, char *, int, int, int, int *, GlobalLU_t *);
                void    print_panel_seg(int, int, int, int, int *, int *);
                void    zcheck_zero_vec(int, char *, int, doublecomplex *);
                void    check_repfnz(int, int, int, int *);


                void *pzgstrf_thread(void *arg);

            };
        };
    };
};

#endif /* __SUPERLU_ZSP_DEFS */

